//
//  ClockAnimalViewController.m
//  UILbrary
//
//  Created by mac on 16/8/17.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ClockAnimalViewController.h"
#import "ClockView.h"
@interface ClockAnimalViewController ()
{
    ClockView *clockView;
    ClockView *clockCodeView;
}
@end

@implementation ClockAnimalViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor lightGrayColor];
    
    clockCodeView = [[ClockView alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 350)];
    
//    clockView = [[[NSBundle mainBundle] loadNibNamed:@"ClockView" owner:self options:nil] lastObject];
//
    [self.view addSubview:clockCodeView];
    
    NSTimer *time = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(clockRun) userInfo:nil repeats:YES];
    clockCodeView.needleImage.layer.anchorPoint = CGPointMake(13.16/26.99, 13.16/23.14);
}

- (void)clockRun{
    NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
    NSUInteger units = NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit;
    NSDateComponents *components = [calendar components:units fromDate:[NSDate date]];
    CGFloat hoursAngle = (components.hour / 12.0) * M_PI * 2.0;
    CGFloat minsAngle = (components.minute / 60.0) * M_PI *2.0;
    CGFloat secsAngle = (components.second / 60.0) *M_PI *2.0;
    clockCodeView.needleImage.transform = CGAffineTransformMakeRotation(secsAngle);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
